﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Web;

namespace Migration.Classes
{
	public static class MigrationLogger
	{
		private const string m_FileName = "~/App_Data/Sitefinity/Logs/Migration.log.htm";
		private static string m_LogText;

		static MigrationLogger()
		{
			m_LogText = String.Empty;
		}

		public static string LogText
		{
			get
			{
				return m_LogText;
			}
		}

		public static void ClearLog()
		{
			m_LogText = String.Empty;
			using (var sw = new StreamWriter(HttpContext.Current.Server.MapPath(m_FileName)))
			{
				sw.Write(String.Empty);
			}
		}

		public static void AppendLogMessage(string message)
		{
			m_LogText += message;
			using (var sw = new StreamWriter(HttpContext.Current.Server.MapPath(m_FileName), true))
			{
				sw.WriteLine(message);
			}
		}

		public static void AppendNewLine()
		{
			m_LogText += "<br/>\n";
			using (var sw = new StreamWriter(HttpContext.Current.Server.MapPath(m_FileName), true))
			{
				sw.WriteLine("<br/>");
			}
		}
	}
}
